<template>
	<view class="container">
		<u--form labelPosition="left" labelWidth="auto">
			<u-form-item label="启用商品栏目">
				<view style="display: flex;justify-content: flex-end;">
					<u-switch v-model="dataForm.is_goods" :activeValue="1" :inactiveValue="0"
						:activeColor="themesColor"></u-switch>
				</view>
			</u-form-item>
			<block v-if="dataForm.is_goods">
				<u-form-item label="圈友可发布商品">
					<view style="display: flex;justify-content: flex-end;">
						<u-switch v-model="dataForm.is_user_add_goods" :activeValue="1" :inactiveValue="0"
							:activeColor="themesColor"></u-switch>
					</view>
				</u-form-item>
				<u-form-item label="栏目名称" labelPosition="top">
					<u--input placeholder="请填写栏目名称" border="surround" v-model="dataForm.goods_class_name"></u--input>
				</u-form-item>
			</block>
		</u--form>

		<q-button shape="circle" @click="onSubmit">保存</q-button>
	</view>
</template>

<script>
	import {
		themesColor
	} from '@/uni.scss';
	export default {
		data() {
			return {
				themesColor,
				dataForm: {
					is_goods: 0,
					is_user_add_goods: 0,
					goods_class_name: ''
				}
			};
		},
		computed: {
			currentTopicId() {
				return this.$store.state.currentTopicId;
			}
		},
		onLoad() {
			this.getTopicInfo()
		},
		methods: {
			onSubmit() {
				if (this.dataForm.is_goods === 1 && !this.dataForm.goods_class_name) {
					uni.showToast({
						icon: "none",
						title: "请填写栏目名称"
					})
					return
				}

				this.dataForm.id = this.currentTopicId;
				this.$H.post("topic/save", this.dataForm).then(res => {
					if (res.code == 1) {
						uni.showToast({
							icon: "none",
							title: "保存成功"
						})
						setTimeout(() => {
							uni.reLaunch({
								url: "/pages/index/index"
							})
						}, 500)
					}
				})
			},
			getTopicInfo() {
				this.$H.get("topic/info", {
					id: this.currentTopicId
				}).then(res => {
					if (res.code == 1) {
						this.dataForm.is_goods = res.result.is_goods;
						this.dataForm.is_user_add_goods = res.result.is_user_add_goods;
						this.dataForm.goods_class_name = res.result.goods_class_name;
					}
				})
			}
		}
	}
</script>

<style lang="scss">

</style>